package com.qf.oa_system.controller;

import com.qf.oa_system.entity.Student;
import com.qf.oa_system.entity.User;
import com.qf.oa_system.entity.Weekly;
import com.qf.oa_system.service.StudentService;
import com.qf.oa_system.service.WeeklyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * ѧ???(Student)表控制层
 *
 * @author makejava
 * @since 2020-06-03 20:26:31
 */
@Controller
@RequestMapping("student")
public class StudentController {
    /**
     * 服务对象
     */
    @Resource
    private StudentService studentService;

    @Autowired
    WeeklyService weeklyService;

    @GetMapping("toWeek")
    public String week(HttpSession session, HttpServletRequest request, Model model){
        User user = (User)session.getAttribute("user");

        Student student = new Student();
        student.setUserId(user.getUserId());

        Student student1 = studentService.queryAllByUserId(user.getUserId());

        List<Weekly> weeklies = weeklyService.queryByStuId(student1.getStuId());

        if(weeklies == null || weeklies.size()==0){
            return "noweek";
        }else {
        model.addAttribute("weekly",weeklies);
        return "week";
        }
    }

}